#include "goldminestates.h"
#include <cassert>
#include "misc/crudetimer.h"
#include "messagedispatcher.h"
#include "telegramtypes.h"

// Methods for UnemptyState
///////////////////////////
UnemptyState* UnemptyState::Instance()
{
	static UnemptyState instance;

	return &instance;
}

/*-------------------------------------------------------------------------------------------------------------*/
void UnemptyState::Enter(GoldMine* pGoldMine)
{
		
}

/*-------------------------------------------------------------------------------------------------------------*/
void UnemptyState::Execute(GoldMine* pGoldMine)
{  
	// If the gold supply hits 0 switch to Empty State
}

/*-------------------------------------------------------------------------------------------------------------*/
void UnemptyState::Exit(GoldMine* pGoldMine)
{

}

/*-------------------------------------------------------------------------------------------------------------*/
bool UnemptyState::OnMessage(GoldMine* pGoldMine, const Telegram& message)
{
	// Send msg to global message handler
	return false;
}

// Methods for EmptyState
/////////////////////////
EmptyState* EmptyState::Instance()
{
	static EmptyState instance;

	return &instance;
}

void EmptyState::Enter(GoldMine* pGoldMine)
{
	
}

/*-------------------------------------------------------------------------------------------------------------*/
void EmptyState::Execute(GoldMine* pGoldMine)
{  
	
}

/*-------------------------------------------------------------------------------------------------------------*/
void EmptyState::Exit(GoldMine* pGoldMine)
{
	
}

/*-------------------------------------------------------------------------------------------------------------*/
bool EmptyState::OnMessage(GoldMine* pGoldMine, const Telegram& message)
{
	// Send msg to global message handler
	return false;
}

// Methods for GoldMineGlobalState
//////////////////////////
GoldMineGlobalState* GoldMineGlobalState::Instance()
{
	static GoldMineGlobalState instance;

	return &instance;
}

/*-------------------------------------------------------------------------------------------------------------*/
void GoldMineGlobalState::Enter(GoldMine* pGoldMine)
{
	
}

/*-------------------------------------------------------------------------------------------------------------*/
void GoldMineGlobalState::Execute(GoldMine* pGoldMine)
{ 
	if(pGoldMine->IsGoldMineEmpty())
	{
		MessageDispatcher::Instance()->DispatchMessage(0, ent_GoldMine, ent_Peon, msg_GoldMineEmpty, NULL);
	}
}

/*-------------------------------------------------------------------------------------------------------------*/
void GoldMineGlobalState::Exit(GoldMine* pGoldMine)
{ 
	
}

/*-------------------------------------------------------------------------------------------------------------*/
bool GoldMineGlobalState::OnMessage(GoldMine* pGoldMine, const Telegram& message)
{
	switch(message.m_iMessage)
	{
		case msg_GoldMined:
			 
			pGoldMine->RemoveGold(*static_cast<int*>(message.m_extraInfo));
			break;

	}
	// Send msg to global message handler
	return true;
}